<?php
/**
 * Created by PhpStorm.
 * User: dengpan
 * Date: 2016/12/7
 * Time: 02:17
 */

// 引入客户端文件
require_once __DIR__ . "/Thrift/ClassLoader/ThriftClassLoader.php";
use Thrift\ClassLoader\ThriftClassLoader;

use Thrift\Server\TServerSocket;
use Thrift\Server\TSimpleServer;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Factory\TTransportFactory;
use Thrift\Factory\TBinaryProtocolFactory;

$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__);
$loader->registerNamespace('Services', __DIR__);
$loader->registerDefinition('Services',  __DIR__);
$loader->register();


$handler = new Services\Hello\Handler();
$processor = new Services\Hello\myServiceProcessor($handler);
$transport = new TServerSocket('0.0.0.0', 1234);
$protocol = new TBinaryProtocol($transport, true, true);
$inTransportFactory = new TTransportFactory();
$outTransportFactory = new TTransportFactory();
$inProtocolFactory = new TBinaryProtocolFactory();
$outProtocolFactory = new TBinaryProtocolFactory();

$out_protocol = $in_protocol = new Thrift\Factory\TBinaryProtocolFactory();
$server = new TSimpleServer($processor, $transport, $inTransportFactory, $outTransportFactory, $inProtocolFactory, $outProtocolFactory);
$server->serve();

